package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.applySupplierBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.getSupplierStatusBean;
import com.ymatou.iapi.godmch.parameter.reApplyAgentBean;
import com.ymatou.iapi.godmch.service.applyAgentCall;
import com.ymatou.iapi.godmch.service.applySupplierCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.getSupplierStatusCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.supplierLog;
import com.ymttest.database.model.godmch.supplierLogExample;
import com.ymttest.database.sqlwapper.godmch.supplierLogWapper;
/**
*供货商状态查询
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getSupplierStatus{
	private static getSupplierStatusBean bean;
	private static getSupplierStatusCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("供货商状态查询");
	}

	@Before
	public void caseUp() {
		bean=new getSupplierStatusBean();
		call=new getSupplierStatusCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}
    /**
     * 1：正常

		2：待审核
		
		3：已删除
		
		4：拒绝
		
		5：重新申请被拒绝（曾经有过审核通过，被删了，再来重新申请被拒绝）
		
		6：重新申请待审核（曾经有过审核通过，被删了，再来重新申请）
     * @param expStatus
     * @throws InterruptedException
     * @throws JSONException
     */
     private void check_verify(Integer expStatus) throws InterruptedException, JSONException
     {
		supplierLogExample supplierLogExample=new supplierLogExample();
		supplierLogWapper supplierLogWapper=new supplierLogWapper();
		supplierLogExample.createCriteria().andMchIdEqualTo(bean.getMchId()).andSupplierIdEqualTo(bean.getSupplierId());
		supplierLogExample.setOrderByClause("  createTime desc ");
		supplierLog supplierLog=  supplierLogWapper.selectByExample(supplierLogExample).get(0);
		
		Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证Message");
		Logger.verifyEquals(expStatus, call.getStatus(), "验证返回供货商status");
		
		//Logger.verifyEquals(expStatus, supplierLog.getLogType(), "验证返回供货商与数据库中的LogType一致");
		
		Logger.verifyEquals(call.getRemark(),(expStatus==4||expStatus==5)?supplierLog.getRemark():"", "验证返回供货商remark");
		
     }
	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierStatus_001() {
//		1：正常
//		2：待审核
//		3：已删除
//		4：拒绝
//		5：重新申请被拒绝（曾经有过审核通过，被删了，再来重新申请被拒绝）
//		6：重新申请待审核（曾经有过审核通过，被删了，再来重新申请）
		Logger.start(true,"正例-供货商状态查询-mchId是无代理独立商户-成功");
		try {
			//创建独立商户1
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            
            bean.setMchId(createIndepMchCall.getmchId());
            bean.setSupplierId(applySupplierCall.getSupplierId());
            
			call.setData(bean);
			call.callService();	
			
			check_verify(2);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierStatus_003() {
		Logger.start(true,"正例-供货商状态查询-mchId是有代理独立商户-正常-成功");
		try {
			//创建独立商户
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请独立商户的代理
            GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            //通过
            GodmchManageCallService.approveSupplier(createIndepMchCall.getmchId(), applySupplierCall.getSupplierId());
            
            bean.setMchId(createIndepMchCall.getmchId());
            bean.setSupplierId(applySupplierCall.getSupplierId());
            
			call.setData(bean);
			call.callService();			
			
			check_verify(1);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierStatus_004() {
		Logger.start(true,"正例-供货商状态查询-mchId是有代理独立商户-待审核-成功");
		try {
			//创建独立商户
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请独立商户的代理
            GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
           
            
            bean.setMchId(createIndepMchCall.getmchId());
            bean.setSupplierId(applySupplierCall.getSupplierId());
			call.setData(bean);
			call.callService();			
			
			check_verify(2);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierStatus_005() {
		Logger.start(true,"正例-供货商状态查询-mchId是有代理独立商户-已删除-成功");
		try {
			//创建独立商户
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请独立商户的代理
            GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            //通过
            GodmchManageCallService.approveSupplier(createIndepMchCall.getmchId(), applySupplierCall.getSupplierId());
            //删除供货商
            GodmchManageCallService.deleteSupplier(createIndepMchCall.getmchId(), applySupplierCall.getSupplierId());
            
            bean.setMchId(createIndepMchCall.getmchId());
            bean.setSupplierId(applySupplierCall.getSupplierId());
			call.setData(bean);
			call.callService();	
			
			call.setData(bean);
			call.callService();			
			
			check_verify(3);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierStatus_006() {
		Logger.start(true,"正例-供货商状态查询-mchId是有代理独立商户-拒绝-成功");
		try {
			//创建独立商户
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请独立商户的代理
            GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            //拒绝
            GodmchManageCallService.rejectSupplier(createIndepMchCall.getmchId(), applySupplierCall.getSupplierId());
            
            bean.setMchId(createIndepMchCall.getmchId());
            bean.setSupplierId(applySupplierCall.getSupplierId());
			call.setData(bean);
			call.callService();			
			
			check_verify(4);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierStatus_007() {
		Logger.start(true,"正例-供货商状态查询-mchId是有代理独立商户-重新申请被拒绝-成功");
		//重新申请被拒绝   是曾经有过审核通过，被删了，再来重新申请被拒绝
		try {
			//创建独立商户
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请独立商户的代理
            GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            //通过
            GodmchManageCallService.approveSupplier(createIndepMchCall.getmchId(), applySupplierCall.getSupplierId());
            //删除
            GodmchManageCallService.deleteSupplier(createIndepMchCall.getmchId(), applySupplierCall.getSupplierId());
            //重新申请供货商
            GodmchManageCallService.ReApplySupplier(createIndepMchCall.getmchId(),applySupplierCall.getSupplierId());
            //重新申请供货商被拒绝
            GodmchManageCallService.rejectSupplier(createIndepMchCall.getmchId(), applySupplierCall.getSupplierId());
            
            bean.setMchId(createIndepMchCall.getmchId());
            bean.setSupplierId(applySupplierCall.getSupplierId());
			call.setData(bean);
			call.callService();			
			
			check_verify(5);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierStatus_008() {
		Logger.start(true,"正例-供货商状态查询-mchId是有代理独立商户-重新申请待审核-成功");
		//重新申请被拒绝   是曾经有过审核通过，被删了，重新申请待审核
		try {
			//创建独立商户
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请独立商户的代理
            GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            //通过
            GodmchManageCallService.approveSupplier(createIndepMchCall.getmchId(), applySupplierCall.getSupplierId());
            //删除
            GodmchManageCallService.deleteSupplier(createIndepMchCall.getmchId(), applySupplierCall.getSupplierId());
            //重新申请供货商
            GodmchManageCallService.ReApplySupplier(createIndepMchCall.getmchId(),applySupplierCall.getSupplierId());
            
            bean.setMchId(createIndepMchCall.getmchId());
            bean.setSupplierId(applySupplierCall.getSupplierId());
			call.setData(bean);
			call.callService();			
			
			check_verify(6);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierStatus_010() {
		Logger.start(true,"正例-供货商状态查询-商户Id是独立商户的代理-失败");
		try {
			//创建独立商户
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请独立商户的代理
            applyAgentCall applyAgentCall=GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            //通过
            GodmchManageCallService.approveSupplier(createIndepMchCall.getmchId(), applySupplierCall.getSupplierId());
            
            bean.setMchId(applyAgentCall.getAgentId());
            bean.setSupplierId(applySupplierCall.getSupplierId());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("供货商不存在"), "验证Message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierStatus_011() {
		Logger.start(true,"反例-供货商状态查询-mchId不存在-失败");
		try {
			//创建独立商户1
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            
            bean.setMchId(createIndepMchCall.getmchId()+1111);
            bean.setSupplierId(applySupplierCall.getSupplierId());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("供货商不存在"), "验证Message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierStatus_012() {
		Logger.start(true,"反例-供货商状态查询-supplierId不存在-失败");
		try {
			//创建独立商户1
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            
            bean.setMchId(createIndepMchCall.getmchId());
            bean.setSupplierId(applySupplierCall.getSupplierId()+11111);
        	call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("供货商不存在"), "验证Message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierStatus_013() {
		Logger.start(true,"反例-供货商状态查询-独立商户与供货商不存在关系-失败");
		try {
			//创建独立商户1
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //创建独立商户2
        	createIndepMchBean createIndepMchBean2=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall2=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean2);
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            
            bean.setMchId(createIndepMchCall2.getmchId());
            bean.setSupplierId(applySupplierCall.getSupplierId());
            
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("供货商不存在"), "验证Message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierStatus_014() {
		Logger.start(true,"反例-供货商状态查询-mchId为空-失败");
		try {
			//创建独立商户1
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            
           // bean.setMchId(createIndepMchCall.getmchId());
            bean.setSupplierId(applySupplierCall.getSupplierId());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierStatus_015() {
		Logger.start(true,"反例-供货商状态查询-supplierId为空-失败");
		try {
			//创建独立商户1
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            
            bean.setMchId(createIndepMchCall.getmchId());
          //  bean.setSupplierId(applySupplierCall.getSupplierId());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}